package router

import (
	"cake-server/apiFun"
	"cake-server/module"

	"github.com/gin-gonic/gin"
)

func UploadRouter(r *gin.Engine) {
	var api = r.Group("/api")
	api.POST("/upload", apiFun.UploadFile)
}
func LoginRouter(r *gin.Engine) {
	var api = r.Group("/api")
	api.POST("/login", apiFun.LoginFun)
	api.POST("/register", apiFun.LoginRegister)
}

func MenuRouter(r *gin.Engine) {
	module.DB.AutoMigrate(&module.Menu{})
	var api = r.Group("/api")
	api.GET("/menus", apiFun.GetMenu)
	api.POST("/menus", apiFun.AddMenu)
	api.PUT("/menus", apiFun.UpdateMenu)
	api.DELETE("/menus", apiFun.DeleteMenu)
}

func UserRouter(r *gin.Engine) {
	var api = r.Group("/api")
	api.GET("/user", apiFun.GetUser)
	api.POST("/user", apiFun.AddUser)
	api.PUT("/user", apiFun.UpdateUser)
	api.DELETE("/user", apiFun.DeleteUser)
	api.GET("/userList", apiFun.GetUser_Roles)
}

func RoleRouter(r *gin.Engine) {
	var api = r.Group("/api")
	api.GET("/role", apiFun.GetRoles)
	api.POST("/role", apiFun.AddRoles)
	api.PUT("/role", apiFun.UpdateRoles)
	api.DELETE("/role", apiFun.DeleteRoles)
	api.POST("/role/bindmenus", apiFun.BindMenu)
	api.GET("/role/getmenus", apiFun.GetRoleMenuIds)
}
